package com.sky.controller.users;

import com.sky.config.DeepSeek;
import com.sky.config.DeepSeek_stream;
import com.sky.dto.*;
import com.sky.entity.Food;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.FoodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/food")
@Api(tags = "药膳相关接口")
public class FoodController {
    @Autowired
    private FoodService foodService;
    @GetMapping("/getAll")
    @ApiOperation(value = "查询所有药膳接口")
    public List<Food> getAll(){
        List<Food> foodList = foodService.getAll();
        return foodList;
    }
    @GetMapping("/page")
    @ApiOperation(value = "药膳分页查询接口")
    public Result<PageResult> pageSelect(FoodPageQueryDTO foodPageQueryDTO){
        PageResult pageResult=foodService.pageQuery(foodPageQueryDTO);
        return Result.success(pageResult);
    }
    @GetMapping("/getFoodById/{id}")
    @ApiOperation(value = "根据ID查询膳食")
    public Result<Food> selectById(@PathVariable Long id){
        Food food=foodService.selectById(id);
        return Result.success(food);
    }
    @GetMapping("/getOneFood/{id}")
    @ApiOperation(value = "根据药膳的ID进行查询")
    public Food getFoodById(@PathVariable Long id){
        Food food=foodService.getFoodById(id);
        return food;
    }

    @PostMapping("/userAddFood")
    @ApiOperation(value = "用户端新增药膳接口")
    public Result userAddFood(@RequestBody AddFoodDTO addFoodDTO){

        foodService.userAddFood(addFoodDTO);
        return Result.success();
    }
    @PostMapping("/addFood")
    @ApiOperation(value = "管理端新增药膳接口")
    public Result addFood(@RequestBody AddFoodDTO addFoodDTO){
        foodService.addFood(addFoodDTO);
        return Result.success();
    }
    @PutMapping("/updateFood")
    @ApiOperation(value = "修改膳食接口")
    public Result<Food> updateFood(@RequestBody UpdateFoodDTO updateFoodDTO){
        foodService.updateFood(updateFoodDTO);
        return Result.success();
    }
    @GetMapping("/getByCategory/{id}")
    @ApiOperation(value = "根据类别查询药膳接口")
    public List<Food> getByCategory(@PathVariable Long id){
        List<Food> foodList=foodService.getByCategory(id);
        return foodList;
    }

    @PostMapping("/getFoodByName")
    @ApiOperation(value = "根据名称查询药膳接口")
    public List<Food> getByName(@RequestBody FoodNameDTO foodName){
        List<Food> foodList=foodService.getByName(foodName);
        return foodList;
    }

    @PostMapping("/getHistoryById")
    @ApiOperation(value = "查询用户的搜索历史")
    public List<String> getHistoryById(@RequestBody HistoryDTO historyDTO){
        List<String> historyList=foodService.getHistoryById(historyDTO);
        return historyList;
    }


    @PostMapping("/addHistory")
    @ApiOperation(value = "添加用户的搜索历史")
    public Result addHistory(@RequestBody HistoryDTO historyDTO){
        foodService.addHistory(historyDTO);
        return Result.success();
    }

    @GetMapping("/getSuggestions/{id}")
    @ApiOperation(value = "获取搜索建议")
    public List<SuggestionsDTO> getSuggestions(@PathVariable Long id){
        Long firstId=id;
//        Long secondId=id+5;
        SuggestionsDTO suggestionsDTO=new SuggestionsDTO();
        suggestionsDTO.setFirstId(firstId);
//        suggestionsDTO.setSecondId(secondId);
        List<SuggestionsDTO> suggestionsList=foodService.getSuggestions(suggestionsDTO);
        return suggestionsList;
    }

    @PostMapping("/status/{status}")
    @ApiOperation(value = "膳食的展示和不展示")
    public Result startOrStop(@PathVariable("status") Long status,Long id){
        foodService.startOrStop(status,id);
        return Result.success();
    }

    @DeleteMapping("/deleteFood/{id}")
    @ApiOperation(value = "删除膳食接口")
    public Result deleteFood(@PathVariable Long id){
        foodService.deleteFood(id);
        return Result.success();
    }

    @PostMapping("/problem")
    @ApiOperation(value = "AI回答问题接口")
    public String answer(@RequestBody AIDTO aidto) throws IOException {
        String condition="生成一道菜品，不要和上一次生成的菜品类似，烹饪方式可以是炒，煮，焖，烤，煎，熬，蒸，等等..." +
                "输出结果不要有英文单词,输出结果的格式要求为按顺序输出，并且加上标号：1.名称：2.功效：3.制作步骤";
        String problem=aidto.getProblem()+condition;
        DeepSeek deepSeek=new DeepSeek();
        String answer = deepSeek.answer(problem,true);
        return answer;
    }

    @PostMapping("/webHuLu")
    @ApiOperation(value = "提问神葫的接口")
    public String webHuLu(@RequestBody AIDTO aidto) throws IOException {
        String condition="";
        String problem=aidto.getProblem()+condition;
        DeepSeek deepSeek=new DeepSeek();
        String answer = deepSeek.answer(problem,false);//有思考过程的显示
        return answer;
    }

    @PostMapping("/askHuLu")
    @ApiOperation(value = "提问神葫的接口")
    public String askHuLu(@RequestBody AIDTO aidto) throws IOException {
        String condition="";
        String problem=aidto.getProblem()+condition;
        DeepSeek deepSeek=new DeepSeek();
        String answer = deepSeek.answer(problem,true);//无思考过程的显示
        return answer;
    }

    @GetMapping("/getCount")
    @ApiOperation(value = "获取药膳的数量")
    public Integer getCount(){
        Integer count=foodService.getCount();
        return count;
    }

}
